<?php

require_once 'PHPUnit/Framework/TestListener.php';

class PostPrintTestListener implements PHPUnit_Framework_TestListener {
	
	protected $log;
	protected $loghandle;
	
	public function __construct(){
		$this->log = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . date("YmdHms").".log";
		$this->loghandle = fopen($this->log,"a+");
	}

    /**
     * A test suite started.
     * @param  PHPUnit_Framework_TestSuite $suite
     * @since  Method available since Release 2.2.0
     */
    public function startTestSuite(PHPUnit_Framework_TestSuite $suite){
    	printf("TestSuite %s started.\n",$suite->getName());
    	fwrite($this->loghandle,"TestSuite ". $suite->getName() . " started.\n");
    }

    /**
     * A test suite ended.
     * @param  PHPUnit_Framework_TestSuite $suite
     * @since  Method available since Release 2.2.0
     */
    public function endTestSuite(PHPUnit_Framework_TestSuite $suite){
    	printf("TestSuit %s ended.\n",$suite->getName());
    	fwrite($this->loghandle, "TestSuit " .$suite->getName()." ended.\n");
    }
	
    /**
     * An error occurred.
     * @param  PHPUnit_Framework_Test $test
     * @param  Exception              $e
     * @param  float                  $time
     */
    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time){
    	printf("Error while running test '%s'.\n",$test->getName());
    	fwrite($this->loghandle,"Error while running test " . $test->getName() . "\n");
    }

    /**
     * A failure occurred.
     * @param  PHPUnit_Framework_Test                 $test
     * @param  PHPUnit_Framework_AssertionFailedError $e
     * @param  float                                  $time
     */
    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time){
    	printf("Test %s failed. \n", $test->getName());
    	fwrite($this->loghandle, "Test " .$test->getName() ." failed. \n");
    }
    /**
     * Incomplete test.
     *
     * @param  PHPUnit_Framework_Test $test
     * @param  Exception              $e
     * @param  float                  $time
     */
    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time){
    	printf("Test %s is incomplete.\n",$test->getName());
    	fwrite($this->loghandle, "Test " . $test->getName() . " is incomplete.\n");
    }

    /**
     * Skipped test.
     *
     * @param  PHPUnit_Framework_Test $test
     * @param  Exception              $e
     * @param  float                  $time
     * @since  Method available since Release 3.0.0
     */
    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time){
    	printf("Test %s has been skipped.\n",$test->getName());
    	fwrite($this->loghandle, "Test " . $test->getName() . " has been skipped.\n");
    }

    /**
     * A test started.
     * @param  PHPUnit_Framework_Test $test
     */
    public function startTest(PHPUnit_Framework_Test $test){
    	printf("Test %s started.\n",$test->getName());
    	fwrite($this->loghandle, "Test " . $test->getName()." started.\n");
    }

    /**
     * A test ended.
     * @param  PHPUnit_Framework_Test $test
     * @param  float                  $time
     */
    public function endTest(PHPUnit_Framework_Test $test, $time){
    	printf("Test %s ended  on %s.\n", $test->getName(), $time);
    	fwrite($this->loghandle, "Test " . $test->getName() . " ended  on " . $time . ".\n");
    }
	
	
}


?>